package com.jkhan.movie.controller;


import com.jkhan.common.result.ResponseEntity;
import com.jkhan.common.result.ResponseEnum;
import com.jkhan.model.DatetimeInfo;
import com.jkhan.movie.service.DatetimeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 日期时间表 前端控制器
 * </p>
 *
 * @author jkhan
 * @since 2023-03-04
 */
@RestController
@RequestMapping("/movie")
public class DatetimeInfoController {

    @Autowired
    public DatetimeInfoService datetimeInfoService;

    @GetMapping("/datetimeInfos")
    public ResponseEntity<List<DatetimeInfo>> getList() {
        List<DatetimeInfo> list = datetimeInfoService.list();
        return ResponseEntity.ok(list);
    }

    @PostMapping("/datetimeInfo")
    public ResponseEntity<String> addOne(@RequestBody DatetimeInfo datetimeInfo) {
        boolean isSuccess = datetimeInfoService.save(datetimeInfo);
        if (!isSuccess) {
            return ResponseEntity.fail();
        }
        return ResponseEntity.build(ResponseEnum.CREATED);
    }

    @DeleteMapping("/datetimeInfo/{id}")
    public ResponseEntity<String> removeOne(@PathVariable Integer id) {
        boolean isSuccess = datetimeInfoService.removeById(id);
        if (!isSuccess) {
            return ResponseEntity.fail();
        }
        return ResponseEntity.build(ResponseEnum.DELETED);
    }

    @PutMapping("/dateTimeInfo")
    public ResponseEntity<String> updateOne(@RequestBody DatetimeInfo datetimeInfo) {
        boolean isSuccess = datetimeInfoService.updateById(datetimeInfo);
        if (!isSuccess) {
            return ResponseEntity.fail();
        }
        return ResponseEntity.ok();
    }

}

